package com.xinshujia.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinshujia.dao.AlarmRecordDao;
import com.xinshujia.dto.AlarmRecordDTO;
import com.xinshujia.entity.AlarmRecordEntity;
import com.xinshujia.service.AlarmRecordService;
import com.xinshujia.service.FunctionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * *************************************
 * *   @author: 野狼上校               **
 * *   @since: 2024-07-19 14:22       **
 * *   @version: 1.0                  **
 * *************************************
 * <p>
 * 预警日志服务实现类
 */
@Service
public class AlarmRecordServiceImpl extends ServiceImpl<AlarmRecordDao, AlarmRecordEntity> implements AlarmRecordService {
    private final AlarmRecordDao alarmRecordDao;
    private final FunctionService functionService;


    public AlarmRecordServiceImpl(AlarmRecordDao alarmRecordDao, FunctionService functionService) {
        this.alarmRecordDao = alarmRecordDao;
        this.functionService = functionService;
    }


    /**
     * 预警操作
     *
     * @param deviceGuid  设备Id
     * @param operateType 操作类型（0：关闭预警， 1： 开启预警， 2： 清除预警）
     */
    @Transactional
    @Override
    public Boolean alarmOperate(String deviceGuid, Integer operateType) {
        return functionService.alarmOperate(deviceGuid, operateType);
    }

    /**
     * 预警次数排序
     */
    @Override
    public List<AlarmRecordDTO> getAlarmOrder() {
        return alarmRecordDao.getAlarmRecords();
    }

    /**
     * 根据Device_guid查询预警记录（多条）
     */
    @Override
    public List<AlarmRecordDTO> getAlarmRecordsByDeviceGuid(String deviceGuid) {
        return alarmRecordDao.getAlarmRecordsByDeviceGuid(deviceGuid);
    }

    /**
     * 根据Id查询
     */
    @Override
    public AlarmRecordDTO getAlarmRecordById(Long id) {
        return alarmRecordDao.getAlarmRecordById(id);
    }

    /**
     * 预警记录处理
     */
    @Override
    public Boolean handlerAlarmRecord(AlarmRecordEntity alarmRecordEntity) {
        alarmRecordEntity.setAlarmStatus(1);
        return alarmRecordDao.updateById(alarmRecordEntity) > 0;
    }

}
